<template>
  <el-form :model="form" :rules="rules" ref="formRef">
    <el-form-item label="微信昵称" :label-width="formLabelWidth">
      <el-input disabled v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="电话" :label-width="formLabelWidth">
      <el-input disabled v-model="form.phone"></el-input>
    </el-form-item>
    <el-form-item label="充值钻石数" prop="scort" :label-width="formLabelWidth">
      <el-input v-model.number="form.scort"></el-input>
    </el-form-item>
    <el-form-item :label-width="formLabelWidth">
      <el-button plain @click="resetForm('formRef')">取消</el-button>
      <el-button type="primary" @click="submitForm('formRef')">确定</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      form: {
        name: "",
        phone: "",
        scort: "",
        customerId: ""
      },
      formLabelWidth: "120px",
      rules: {
        scort: [
          { required: true, message: "请输入钻石", trigger: "blur" },
          { type: "number", message: "请输入正确的钻石数量" }
        ]
      }
    };
  },
  methods: {
    initData(wechatNick, phone, customerId) {
      this.form.name = wechatNick;
      this.form.phone = phone;
      this.form.customerId = customerId;
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          //   this.$refs[formName].resetFields();
          //   this.$emit("submit", this.form.scort);
          //   this.$service.homePay(
          //     {
          //       customerId: this.form.customerId, // 用户标识
          //       scort: this.form.scort //积分
          //     },
          //     res => {
          //       console.log(res);
          //     }
          //   );

          this.$service
            .homePay({
              customerId: this.form.customerId, // 用户标识
              scort: this.form.scort //积分
            })
            .then(res => {
              this.$message({
                message: "修改成功",
                type: "success"
              });
              this.$emit("submit", false);
            });
        }
      });
    },
    resetForm(formName) {
      this.$emit("submit", false);
      this.$refs[formName].resetFields();
    }
  }
};
</script>

<style>
</style>